package com.cell.foodie.front.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.cell.foodie.back.user.entity.User;
import com.cell.foodie.front.user.service.LoginService;

/**
 * 前台用户登录模块控制器
 * @author huhu
 *
 */
@Controller("userLoginController")
@RequestMapping("/user_login")
public class loginController {
  @Autowired
  LoginService loginService;//自动装配前台用户登录服务接口bean
  
  /**
   * 显示注册页面
   * @return
   */
  @RequestMapping(value="/register",method=RequestMethod.GET)
  public String register() {
    return "front/register";
  }
  /**
   * 注册验证，并添加用户
   * @param user
   * @return
   */
  @RequestMapping(value="/register",method=RequestMethod.POST)
  public String register(User user) {
    /*
     *查询用户名是否存在
     *若存在返回， 
     */
    loginService.register(user);
    return "redirect:/user_login/register_success"; 
  }
  
  /**
   * 显示注册成功页面
   * @return
   */
  @RequestMapping(value="/register_success",method=RequestMethod.GET)
  public String registerSuccess() {
    return "front/register_success";
  }
  
  /**
   * 显示登录页面
   * @return
   */
  @RequestMapping(value="/login",method=RequestMethod.GET)
  public String login() {
    return "front/new_login"; 
  }

}
